<?php
// +----------------------------------------------------------------------
// | RXThinkCMF_EVTP5.1_PRO前后端分离旗舰版框架 [ RXThinkCMF ]
// +----------------------------------------------------------------------
// | 版权所有 2018~2021 南京RXThinkCMF研发中心
// +----------------------------------------------------------------------
// | 官方网站: http://www.rxthink.cn
// +----------------------------------------------------------------------
// | 作者: ZhangXuanNeng <rxthinkcmf@163.com>
// +----------------------------------------------------------------------
// | 免责声明:
// | 本软件框架禁止任何单位和个人用于任何违法、侵害他人合法利益等恶意的行为，禁止用于任何违
// | 反我国法律法规的一切平台研发，任何单位和个人使用本软件框架用于产品研发而产生的任何意外
// | 、疏忽、合约毁坏、诽谤、版权或知识产权侵犯及其造成的损失 (包括但不限于直接、间接、附带
// | 或衍生的损失等)，本团队不承担任何法律责任。本软件框架只能用于公司和个人内部的法律所允
// | 许的合法合规的软件产品研发，详细声明内容请阅读《框架免责声明》附件；
// +----------------------------------------------------------------------

namespace app\admin\model;


use think\Db;

/**
 * 举报记录-模型
 * @author ZhangXuanNeng
 * @since: 2023/10/13
 * Class BoxReport
 * @package app\admin\model
 */
class BoxReport extends BaseModel
{
    // 设置数据表名
    protected $name = "box_report";

    const TYPE_TOPIC = 1;
    const TYPE_COMMENT = 2;

    const STATUS_UNHANDLED = 0;
    const STATUS_GUILT = 1;
    const STATUS_NOT_GUILT = 2;

    const DEAL_STATUS_FORGIVE = 0;
    const DEAL_STATUS_PUNISH = 1;

    const NOT_DEL_CONTENT = 0;
    const DEL_CONTENT = 1;

    /**
     * 获取缓存信息
     * @param int $id 记录ID
     * @return \app\common\model\数据信息|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @author ZhangXuanNeng
     * @since: 2023/10/13
     */
    public function getInfo($id)
    {
        $info = parent::getInfo($id); // TODO: Change the autogenerated stub
        if ($info) {
            $beRepostUserId = $info['target_member_id'];
            $users = Member::all([$info['member_id'], $beRepostUserId,])->toArray();
            $users = array_column($users, null, 'id');
            $info['deal_username'] = Db::name('user')->where('id',$info['deal_userid'])->value('realname');;
            $info['member_nickname'] = $users[$info['member_id']]['nickname'] ?? '';
            $info['target_member_id'] = $beRepostUserId;
            $info['target_member_nickname'] = $users[$beRepostUserId]['nickname'] ?? '';
            $info['ban_status'] = '';
            $targetMemberBanArr = BanLog::all(['member_id' => $beRepostUserId,])->order('type','asc')->toArray();
            $time = time();
            if ($targetMemberBanArr) {
                foreach ($targetMemberBanArr as $item) {
                    if ($item['type'] == BanLog::TYPE_ACCOUNT && $item['ban_time'] > $time) {
                        $info['ban_status'] .= '封禁账号至' . date('Y-m-d H:i:s', $item['ban_time']);
                    }
                    if ($info['ban_status']) {
                        $info['ban_status'] .= ',';
                    }
                    if ($item['type'] == BanLog::TYPE_COMMENT && $item['ban_time'] > $time) {
                        $info['ban_status'] .= '禁止评论至' . date('Y-m-d H:i:s', $item['ban_time']);
                    }
                }
            }
        }
        return $info;
    }

    /**
     * 获取举报列表
     * @param array $info 举报信息
     * @param array $params 其他参数
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author ZhangXuanNeng
     * @since: 2023/10/13
     */
    public function getReportList($info = [],$params = [])
    {
        if ($info) {
            $beRepostUserId = $info['target_member_id'];
            $users = Member::all([$info['member_id'], $beRepostUserId,])->toArray();
            $users = array_column($users, null, 'id');
            $info['deal_username'] = Db::name('user')->where('id',$info['deal_userid'])->value('realname');;
            $info['member_nickname'] = $users[$info['member_id']]['nickname'] ?? '';
            $info['target_member_id'] = $beRepostUserId;
            $info['target_member_nickname'] = $users[$beRepostUserId]['nickname'] ?? '';
            $info['ban_status'] = '';
            $targetMemberBanArr = BanLog::all(['member_id' => $beRepostUserId,])->order('type','asc')->toArray();
            $time = time();
            if ($targetMemberBanArr) {
                foreach ($targetMemberBanArr as $item) {
                    if ($item['type'] == BanLog::TYPE_ACCOUNT && $item['ban_time'] > $time) {
                        $info['ban_status'] .= '封禁账号至' . date('Y-m-d H:i:s', $item['ban_time']);
                    }
                    if ($info['ban_status']) {
                        $info['ban_status'] .= ',';
                    }
                    if ($item['type'] == BanLog::TYPE_COMMENT && $item['ban_time'] > $time) {
                        $info['ban_status'] .= '禁止评论至' . date('Y-m-d H:i:s', $item['ban_time']);
                    }
                }
            }
        }
        return $info;
    }

}
